#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

#define P pair<int, int>
#define X first
#define Y second
#define LS(x) node[(x)].ch[0]
#define RS(x) node[(x)].ch[1]

const int N = 2 * 1e5 + 5;

P a[N];

int ans[N], ans_tot;
const int INF = 0x3f3f3f3f;
struct Splay {
	struct Node {
		int fa, ch[2];
		bool rev;
		int val, add, maxx, size;
		void init(int _val) {
			val = maxx = _val;
			size = 1;
			add = rev = ch[0] = ch[1] = 0;
		}
	} node[N];
	int root;
	int tot;

	void up(int x) {
		node[x].maxx = max(node[x].val, max(node[LS(x)].maxx, node[RS(x)].maxx));
		node[x].size = node[LS(x)].size + node[RS(x)].size + 1;
	}

	void down(int x) {
		if (x == 0) return ;
		if (node[x].add) {
			if (LS(x)) {
				node[LS(x)].val += node[x].add;
				node[LS(x)].maxx += node[x].add;
				node[LS(x)].add += node[x].add;
			}
			if (RS(x)) {
				node[RS(x)].val += node[x].add;
				node[RS(x)].maxx += node[x].add;
				node[RS(x)].add += node[x].add;
			}
			node[x].add = 0;
		}
		if (node[x].rev) {
			if (LS(x)) node[LS(x)].rev ^= 1;
			if (RS(x)) node[RS(x)].rev ^= 1;
			swap(LS(x), RS(x));
			node[x].rev = 0;
		}
	}

	void rotate(int x, bool kind) {
		int fx = node[x].fa;
		int ffx = node[fx].fa;
		node[fx].ch[!kind] = node[x].ch[kind];
		node[node[x].ch[kind]].fa = fx;

		node[x].ch[kind] = fx;
		node[fx].fa = x;

		node[ffx].ch[RS(ffx) == fx] = x;
		node[x].fa = ffx;
		up(fx);
	}

	void splay(int x, int goal) {
		while (node[x].fa != goal) {
			int fx = node[x].fa;
			int ffx = node[fx].fa;
			down(ffx); down(fx); down(x);
			bool rotate_x = (LS(fx) == x);
			bool rotate_fx = (LS(ffx) == fx);
			if (ffx == goal) rotate(x, rotate_x);
			else {
				if (rotate_x == rotate_fx) rotate(fx, rotate_fx);
				else rotate(x, rotate_x);
				rotate(x, rotate_fx);
			}
		}
		up(x);
		if (goal == 0) root = x;
	}

	int select(int pos) {
		int u = root;
		down(u);
		while (node[LS(u)].size != pos) {
			if (pos < node[LS(u)].size)
				u = LS(u);
			else {
				pos -= node[LS(u)].size + 1;
				u = RS(u);
			}
			down(u);
		}
		return u;
	}

	void insert(int p, int x) {
		int u = select(p);
		splay(u, 0);
		node[tot].init(x);
		LS(tot) = LS(u);
		node[LS(u)].fa = tot;
		LS(u) = tot;
		node[tot].fa = u;
		++tot;
	}

	int build(int L, int R) {
		if (L > R) return 0;
		if (L == R) return L;
		int mid = (L + R) >> 1;
		int r_L, r_R;
		LS(mid) = r_L = build(L, mid - 1);
		RS(mid) = r_R = build(mid + 1, R);
		node[r_L].fa = node[r_R].fa = mid;
		up(mid);
		return mid;
	}

	void init(int n) {
		node[0].init(0); node[0].size = 0;
		node[1].init(0);
		node[n + 2].init(0);
		for (int i = 2; i <= n + 1; ++i)
			node[i].init(0);

		root = build(1, n + 2);
		node[root].fa = 0;

		node[0].fa = 0;
		LS(0) = root;

		tot = 3;
	}

	void print(int u) {
		if(u == 0) return ;
		down(u);
		print(LS(u));
		if(node[u].val)
			ans[ans_tot++] = node[u].val;
		print(RS(u));
	}
} splay_tree;

bool cmp(P a, P b) {
	return a.X > b.X;
}

void gao(int n) {
	ans_tot = 0;
	splay_tree.init(0);
	int flag = 1;
	for(int i = 0; i < n; ++i) {
		if(a[i].Y <= i) {
			int pos = min(a[i].Y, i - a[i].Y);
			splay_tree.insert(pos, a[i].X);
		} else {
			flag = 0;
			break;
		}
	}
	if(flag == 0) {
		puts("impossible");
	} else {
		splay_tree.print(splay_tree.root);
		for(int i = 0; i < ans_tot; ++i) {
			printf("%d%c", ans[i], i == ans_tot - 1 ? '\n' : ' ');
		}
	}
}

int main() {
	int T;
	scanf("%d", &T);
	int cas = 0;
	while(T--) {
		int n;
		scanf("%d", &n);
		for(int i = 0; i < n; ++i) {
			scanf("%d%d", &a[i].X, &a[i].Y);
		}
		sort(a, a + n, cmp);
		printf("Case #%d: ", ++cas);
		gao(n);
	}
	return 0;
}
